#include <iostream> 

using namespace std;

template<int N>
class A
{
public:
  int _arr[N];
};

template<class T, int N = 4>
class B
{
public:
  T _arr[N];
};

void test1()
{
  //const int n = 9;
  A<10> a;
  a._arr[9] = 1;
  cout << a._arr[9] << endl;
  B<int> b;
  b._arr[3] = 0;
  cout << b._arr[3] << endl;
}

template<class T>
bool Less(T a, T b)
{
  return a < b;
}

template<>
bool Less(int* a, int* b)
{
  return *a < *b;
}

template<class T>
int Add(T a, T b)
{
  return a + b;
}

template<>
int Add(int* a, int* b)
{
  return *a + *b;
}

void test2()
{
  int a = 1;
  int b = 2;
//  cout << Less(a, b) << endl;
//  cout << Less(&a, &b) << endl;

  cout << Add(a, b) << endl;
}

template<class T1, class T2>
class Test3 
{
public:
  Test3()
  { cout << "Test3(T1, T1)" << endl; }
};

template<>
class Test3<int, char> 
{
public:
  Test3()
  { cout << "Test3(int, char)" << endl; }
};
template<class T>
class Test3<T&, T&> 
{
public:
  Test3()
  { cout << "Test3(T&, T&)" << endl; }
};

template<class T>
class Test3<T*, T*> 
{
public:
  Test3()
  { cout << "Test3(T*, T*)" << endl; }
};
template<class T1, class T2>
class Test3<T1&, T2*> 
{
public:
  Test3()
  { cout << "Test3(T1&, T2*)" << endl; }
};
template<class T>
class Test3<T, int> 
{
public:
  Test3()
  { cout << "Test3(T, int)" << endl; }
};


void test3()
{
  // 测试偏特化
// Test3<int, char> t1; 
//  Test3<char, int> t2;
//  Test3<int&, int&> t3;
//  Test3<int*, int*> t4;
  Test3<int&, char*> t5;
}

#include "Test.h"
void test4()
{
  // 模板的分离编译
  Test4<int> a(114);
  cout << a.Print() << endl;
  cout << a.callcval() << endl;
  Test4<char> b('Y');
  cout << b.Print() << endl;
  cout << b.callcval() << endl;
}

int main()
{
  test4();
  return 0;
}
